package tutorial.lite_mod.forum_bbs;

import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import public_util.model.Const4PublicDataBase;
import public_util.model.PublicMiddleTable;
import public_util.model.PublicUserInfo;
import public_util.model.ReturnData;
import system_api_4_trade.dao.ApiPublicMiddleTableMapper;
import system_api_4_trade.util.sql.SelectTool;
import system_api_4_trade.util.tool_4_handle.Tool_4_ServletApi;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

/**
 * 这个类用来提供给before和after方法使用,用于MiddleTable的返回
 * http://note.youdao.com/noteshare?id=ff1fcad63bc82be1f5d380dd56e8efc2
 */
public class TemplateUtilApi {

    private static Logger logger = Logger.getLogger(TemplateUtilApi.class);




    /**
     * 验证链接: duzikai_api_mgr_public_middle_table?invoke_method=public_load_middle_table_list&pre_db_para_middle_table_name=public_middle_table_lite_mod_forum_bbs&pre_db_para_begin_idx=0&pre_db_para_length_4_list=10&pre_cmd_para_show_main_info=true
     * 工具零件方法
     * 组装方法: 主要是在before活着after方法里面调用
     * 根据这个零件来拼装
     * @return
     */
    public static ReturnData pre_cmd_para_show_main_info(List<PublicMiddleTable> tbList, HttpServletRequest request, SqlSession session, HashMap<String, Object> params2db, ReturnData resultData)
    {
        ApiPublicMiddleTableMapper middleTableMapper = session.getMapper(ApiPublicMiddleTableMapper.class);
        String pre_cmd_para_show_main_info = request.getParameter("pre_cmd_para_show_main_info");
        PublicUserInfo userInfo = (PublicUserInfo) Tool_4_ServletApi.getAttribute(null, request.getSession(),Const4PublicDataBase.MEM_4_self_public_user_info);
        if ("true".equals(pre_cmd_para_show_main_info))
        {
            for (int i = 0; i < tbList.size(); i++)
            {
                PublicMiddleTable subArrangeData = tbList.get(i);
                int id_public_middle_table = subArrangeData.getId_public_middle_table();//ID
                if (id_public_middle_table <= 0)
                {
                    logger.error("没有设置mid_table_remark_015的信息");
                    continue;
                }
                int type_middle_app = subArrangeData.getType_middle_app();
                if (type_middle_app == 62001)
                {

                    HashMap<String, Object> search015 = new HashMap<>();
                    search015.put(Const4PublicDataBase.PARA_mid_table_remark_015+ "_in", id_public_middle_table);
                    search015.put(Const4PublicDataBase.PARA_type_middle_app+ "_in", 63001);
                    search015.put(Const4PublicDataBase.PARA_type_inner_app+ "_in", 1001);
                    search015.put("is_online", "0");
                    HashMap<String, Object>  realPara = SelectTool.paramap2selectMap(search015, "public_middle_table_lite_mod_forum_bbs");
                    List<PublicMiddleTable> pinglunAll = middleTableMapper.tableDataList(realPara);// 周期的配置
                    int pinglun_num = 0;
                    if (pinglunAll != null)
                    {
                        pinglun_num = pinglunAll.size();
                    }
                    subArrangeData.setSave_data_001(pinglun_num);


                    search015 = new HashMap<>();
                    search015.put(Const4PublicDataBase.PARA_mid_table_remark_015+ "_in", id_public_middle_table);
                    search015.put(Const4PublicDataBase.PARA_type_middle_app+ "_in", 64001);
                    search015.put(Const4PublicDataBase.PARA_type_inner_app+ "_in", 1001);
                    search015.put("is_online", "0");
                    realPara = SelectTool.paramap2selectMap(search015, "public_middle_table_lite_mod_forum_bbs");
                    List<PublicMiddleTable> dianzanAll = middleTableMapper.tableDataList(realPara);// 周期的配置
                    int dianzan_num = 0;
                    if (dianzanAll != null)
                    {
                        dianzan_num = dianzanAll.size();
                    }
                    subArrangeData.setSave_data_002(dianzan_num);

                    subArrangeData.setSave_data_003("");
                    if (userInfo != null)
                    {
                        HashMap<String, Object> search016 = new HashMap<>();
                        search016.put(Const4PublicDataBase.PARA_mid_table_remark_015+ "_in", id_public_middle_table);
                        search016.put(Const4PublicDataBase.PARA_mid_table_remark_016+ "_in", userInfo.getId_public_user_info());
                        search016.put(Const4PublicDataBase.PARA_type_middle_app+ "_in", 64001);
                        search016.put(Const4PublicDataBase.PARA_type_inner_app+ "_in", 1001);
                        search016.put("is_online", "0");

                        realPara = SelectTool.paramap2selectMap(search016, "public_middle_table_lite_mod_forum_bbs");
                        List<PublicMiddleTable> selfzan = middleTableMapper.tableDataList(realPara);// 周期的配置
                        subArrangeData.setSave_data_003(selfzan);
                    }



                }
            }
        }
        return null;
    }





    /**
     * 验证链接: duzikai_api_mgr_public_middle_table?invoke_method=public_load_middle_table_list&pre_db_para_middle_table_name=public_middle_table_lite_mod_forum_bbs&pre_db_para_begin_idx=0&pre_db_para_length_4_list=10&pre_cmd_para_show_main_info=true
     * 工具零件方法
     * 组装方法: 主要是在before活着after方法里面调用
     * 根据这个零件来拼装
     * @return
     */
    public static ReturnData pre_cmd_para_show_answer_info(List<PublicMiddleTable> tbList, HttpServletRequest request, SqlSession session, HashMap<String, Object> params2db, ReturnData resultData)
    {
        ApiPublicMiddleTableMapper middleTableMapper = session.getMapper(ApiPublicMiddleTableMapper.class);
        String pre_cmd_para_show_answer_info = request.getParameter("pre_cmd_para_show_answer_info");
        PublicUserInfo userInfo = (PublicUserInfo) Tool_4_ServletApi.getAttribute(null, request.getSession(),Const4PublicDataBase.MEM_4_self_public_user_info);
        if ("true".equals(pre_cmd_para_show_answer_info))
        {
            for (int i = 0; i < tbList.size(); i++)
            {
                PublicMiddleTable subArrangeData = tbList.get(i);
                int id_public_mid_table = subArrangeData.getId_public_middle_table();//ID
                if (id_public_mid_table <= 0)
                {
                    logger.error("没有设置mid_table_remark_020的信息");
                    continue;
                }
                int type_middle_app = subArrangeData.getType_middle_app();
                if (type_middle_app == 63001)
                {
                    HashMap<String, Object> search015 = new HashMap<>();
                    search015.put(Const4PublicDataBase.PARA_mid_table_remark_020+ "_in", id_public_mid_table);
                    search015.put(Const4PublicDataBase.PARA_type_middle_app+ "_in", 65001);
                    search015.put(Const4PublicDataBase.PARA_type_inner_app+ "_in", 1001);
                    search015.put("is_online", "0");
                    HashMap<String, Object>  realPara = SelectTool.paramap2selectMap(search015, "public_middle_table_lite_mod_forum_bbs");
                    List<PublicMiddleTable> dianzanAll = middleTableMapper.tableDataList(realPara);// 周期的配置
                    int dianzan_num = 0;
                    if (dianzanAll != null)
                    {
                        dianzan_num = dianzanAll.size();
                    }
                    subArrangeData.setSave_data_002(dianzan_num);


                    subArrangeData.setSave_data_003("");
                    if (userInfo != null)
                    {
                        HashMap<String, Object> search016 = new HashMap<>();
                        search016.put(Const4PublicDataBase.PARA_mid_table_remark_020+ "_in", id_public_mid_table);
                        search016.put(Const4PublicDataBase.PARA_mid_table_remark_016+ "_in", userInfo.getId_public_user_info());
                        search016.put(Const4PublicDataBase.PARA_type_middle_app+ "_in", 65001);
                        search016.put(Const4PublicDataBase.PARA_type_inner_app+ "_in", 1001);
                        search016.put("is_online", "0");

                        realPara = SelectTool.paramap2selectMap(search016, "public_middle_table_lite_mod_forum_bbs");
                        List<PublicMiddleTable> selfzan = middleTableMapper.tableDataList(realPara);// 周期的配置
                        subArrangeData.setSave_data_003(selfzan);
                    }
                }
            }
        }
        return null;
    }





}
